package com.acme.bankapp.domain.bank.account;

import com.acme.bankapp.domain.bank.account.AbstractAccount;
import com.acme.bankapp.exception.bank.NotEnoughFundsException;

public class SavingAccount extends AbstractAccount {


    public SavingAccount(double balance) {
        if (balance < 0) {
            throw new IllegalArgumentException();
        }
        this.balance = balance;
    }


    public void withdraw(double x) throws NotEnoughFundsException {

        if (this.balance >= x) {
            this.balance -= x;
            return;
        } else
            throw new NotEnoughFundsException("NotEnoughFundsException\n");
    }


    public double maximumAmountToWithdraw() {

        return this.balance;
    }

    @Override
    public String toString() {
        return String.format("Saving account: %.2f \nInteger value of balance: %d\n", getBalance(), decimalValue());
    }

}